<?php

/**
 * feed actions.
 *
 * @package    blogallery
 * @subpackage feed
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class feedActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeIndex()
  {
    $this->forward('feed', 'post');
  }
  
  public function executePost()
  {
    $feed = new sfAtom1Feed();

    $feed->initialize(array(
      'title'       => sfConfig::get('app_site_title'),
      'link'        => '@homepage',
      'authorName'  => sfConfig::get('app_site_author')
    ));
      	
    $c = new Criteria();
 	$c->add(PostPeer::PUBLISHED, '1');
    $c->addJoin(PostPeer::ID, PostI18nPeer::ID);
    $c->add(PostI18nPeer::CULTURE, $this->getUser()->getCulture());
    $c->addAscendingOrderByColumn(PostPeer::DATETIME);
    $c->setLimit('10');
 	
    $posts = PostPeer::doSelectWithI18n($c);
       
    foreach ($posts as $post)
  	{  		
  	  $post->setCulture($this->getUser()->getCulture());
  	  $url = '@default?lang='.$this->getUser()->getLang().'&module=post&action=show&handle='.$post->getHandle();
  	
      $item = new sfFeedItem();
      $item->initialize(array(
        'uinqueId' => $url,
        'title' => $post->getTitle(),  	
        'pubdate' => $post->getDatetime(),
        'authorName' => sfConfig::get('app_site_author'),
        'description' => $post->getContent(),
        'link' => $url,
        'categories' => $post->getTagArray(),
      ));
    
      $feed->addItem($item);
  	}
  	
    $this->feed = $feed;
  }
}
